// 考试接口
import {request} from '../utils/request'

const examApi = {
  examSearch: '/exam/search',
  findAllSubject: '/subject/findAllSubjects',
  examAdd: '/exam/add',
  getStudent: '/mark/getStudentList',
  getAnswerPaperOfExam: '/mark/getAnswerPaperOfExam',
  search: '/questionBank/liberary/search',
  addQuestionToPaper: '/question/addQuestionToPaper',
  addPaper: '/exam/addPaper',
  getPaper: '/mark/getPaperOfExam',
  deletePaper: '/exam/deletePaper',
  addStudent: '/exam/addStudentListToExam',
  getQuestionList: '/mark/getQuestionList',
  getExamById: '/exam/getExamById',
  examRelease: '/exam/release',
  examStart: '/exam/start',
  examPause: '/exam/pause',
  examFinish: '/exam/finish',
  computeObjectiveQuestion: '/exam/computeObjectiveQuestion',
  updateSubjectiveQuestion: '/exam/updateSubjectiveQuestion',
  getStudentAnswer: '/mark/getStudentAnswer',
  getSumScore: '/mark/getSumScore',
  releaseScore: '/exam/releaseScore',
  getAnswerPaperOfExamInfo: '/mark/getAnswerPaperInfoOfExam',
  deleteExam: '/exam/delete'
}

// 根据教师查找考试
export function examSearchByTeacher (parameters) {
  return request({
    url: examApi.examSearch,
    method: 'get',
    params: {
      teacherId: parameters.teacherId,
      page_size: parameters.page_size,
      index: parameters.index
    }
  })
}

// 根据教师查找考试
export function examSearch (parameters) {
  return request({
    url: examApi.examSearch,
    method: 'get',
    params: {
      teacherId: parameters.teacherId,
      subjectId: parameters.subjectId,
      status: parameters.status,
      status2: parameters.status2,
      page_size: parameters.page_size,
      index: parameters.index
    }
  })
}

// 根据教师账号和状态查找题目
export function examSearchByStatusAndTeacher (status) {
  return request({
    url: examApi.examSearch,
    method: 'get',
    params: {
      teacherId: sessionStorage.getItem('teacherId'),
      status: status
    }
  })
}

// 根据教师账号和考试名称
export function examSearchByNameAndTeacher (name) {
  return request({
    url: examApi.examSearch,
    method: 'get',
    params: {
      teacherId: sessionStorage.getItem('teacherId'),
      name: name
    }
  })
}

// 根据关键字查找题目
export function examSearchByName (name) {
  return request({
    url: examApi.examSearch,
    method: 'get',
    params: {
      name: name
    }
  })
}

// 查询所有考试
export function findAllSubject () {
  return request({
    url: examApi.findAllSubject,
    method: 'get'
  })
}

// 增加考试
export function examAdd (examInfo) {
  return request({
    url: examApi.examAdd,
    method: 'post',
    data: {
      createTime: '',
      endTime: examInfo.endTime,
      name: examInfo.name,
      startTime: examInfo.startTime,
      subjectId: examInfo.subjectId,
      teacherId: examInfo.teacherId,
      updateTime: ''
    }
  })
}

// 查找某场考试的学生
export function getStudent (info) {
  return request({
    url: examApi.getStudent,
    method: 'get',
    params: {
      examId: info.examId,
      index: info.index,
      pageSize: info.pageSize
    }
  })
}

// 查找某场考试的答题卡id
export function getAnswerPaperOfExam (examId) {
  return request({
    url: examApi.getAnswerPaperOfExam,
    method: 'get',
    params: {
      examId: examId
    }
  })
}

// 查找某场考试的答题卡
export function getAnswerPaperOfExamInfo (info) {
  return request({
    url: examApi.getAnswerPaperOfExamInfo,
    method: 'get',
    params: {
      examId: info.examId,
      page_size: info.page_size,
      index: info.index
    }
  })
}

// 根据老师查找题库
export function search (teacherId) {
  return request({
    url: examApi.search,
    method: 'get',
    params: {
      teacherId: teacherId
    }
  })
}

// 增加试题
export function addQuestionToPaper (info) {
  return request({
    url: examApi.addQuestionToPaper,
    method: 'post',
    params: {
      paperId: info.paperId,
      questionId: info.questionId + ''
    },
    data: info.questionOrder
  })
}

// 为考试增加试卷
export function addPaper (paperInfo) {
  return request({
    url: examApi.addPaper,
    method: 'post',
    params: {
      examId: paperInfo.examId
    },
    data: {
      createTime: '',
      examId: paperInfo.examId,
      scoreItemsJSONStr: paperInfo.scoreItemsJSONStr,
      updateTime: ''
    }
  })
}

// 获取某场考试试卷
export function getPaper (examId) {
  return request({
    url: examApi.getPaper,
    method: 'get',
    params: {
      examId: examId
    }
  })
}

// 删除某场考试试卷
export function deletePaper (examId) {
  return request({
    url: examApi.deletePaper,
    method: 'delete',
    params: {
      examId: examId
    }
  })
}

// 增加学生
export function addStudent (info) {
  return request({
    url: examApi.addStudent,
    method: 'post',
    params: {
      examId: info.examId
    },
    data: info.studentNumberList
  })
}

// 获取试卷题目
export function getQuestionList (info) {
  return request({
    url: examApi.getQuestionList,
    method: 'get',
    params: {
      index: info.index,
      pageSize: info.pageSize,
      paperId: info.paperId
    }
  })
}

// 获取试卷题目
export function getExamById (examId) {
  return request({
    url: examApi.getExamById,
    method: 'get',
    params: {
      examId: examId
    }
  })
}

// 开始考试
export function examRelease (examId) {
  return request({
    url: examApi.examRelease,
    method: 'post',
    params: {
      examId: examId
    }
  })
}

// 开始考试
export function examStart (examId) {
  return request({
    url: examApi.examStart,
    method: 'post',
    params: {
      examId: examId
    }
  })
}

// 暂停考试
export function examPause (examId) {
  return request({
    url: examApi.examPause,
    method: 'post',
    params: {
      examId: examId
    }
  })
}

// 结束考试
export function examFinish (examId) {
  return request({
    url: examApi.examFinish,
    method: 'post',
    params: {
      examId: examId
    }
  })
}

// 批阅客观题
export function computeObjectiveQuestion (info) {
  return request({
    url: examApi.computeObjectiveQuestion,
    method: 'post',
    params: {
      examId: info.examId,
      isOver: info.isOver,
      questionType: info.questionType,
      singleScore: info.singleScore,
      answerPaperIdList: info.answerPaperList + ''
    }
  })
}

// 批阅客观题
export function updateSubjectiveQuestion (info) {
  return request({
    url: examApi.updateSubjectiveQuestion,
    method: 'post',
    params: {
      answerPaperId: info.answerPaperId,
      score: info.score
    },
    data: info.answerList
  })
}

// 获取学生答题卡某道题答案
export function getStudentAnswer (info) {
  return request({
    url: examApi.getStudentAnswer,
    method: 'get',
    params: {
      answerPaperId: info.answerPaperId,
      questionId: info.questionId
    }
  })
}

// 根据答题卡id获取分数
export function getSumScore (answerPaperId) {
  return request({
    url: examApi.getSumScore,
    method: 'get',
    params: {
      answerPaperId: answerPaperId
    }
  })
}

// 发布成绩
export function releaseScore (info) {
  return request({
    url: examApi.releaseScore,
    method: 'post',
    params: {
      examId: info.examId,
      teacherNumber: info.teacherNumber
    }
  })
}

// 删除某场考试
export function deleteExam (info) {
  return request({
    url: examApi.deleteExam,
    method: 'post',
    params: {
      examId: info.examId,
      teacherNumber: info.teacherNumber
    }
  })
}
